package com.atguigu.cloud.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @BelongsProject: cloud2024
 * @BelongsPackage: com.atguigu.cloud.controller
 * @Description: 为断路器提供的接口，测试断路器。
 */

@RestController
public class PayCircuitController {


    @GetMapping(value = "/pay/circuit/{id}")
    public String myCircuit(@PathVariable("id") Integer id) {
        if (id == -4) throw new RuntimeException("circuit id 不能为负数");

        if (id == 9999) {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        return "hello,circuit";
    }


    @GetMapping(value = "/pay/bulkhead/{id}")
    public String myBulkHead(@PathVariable("id") Integer id) {
        if (id == -4) throw new RuntimeException("BulkHead id 不能为负数");

        if (id == 9999) {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "hello,BulkHead";
    }


    @GetMapping(value = "/pay/rateLimit/{id}")
    public String myRateLimit(@PathVariable("id") Integer id) {
        return "hello,rateLimit";
    }
}